<template>
  <div class="Login_container">
    <div class="Login_box">
      <el-form :model="form" :rules="rules" ref="formRef" label-width="0px" class="Login_Form">
        <h1>Login</h1>
        <el-form-item prop="user">
          <el-input v-model="form.user" prefix-icon="el-icon-user" placeholder="请输入内容"></el-input>
        </el-form-item>
        <br>
        <el-form-item prop="password">
          <el-input placeholder="请输入密码" v-model="form.password" prefix-icon="el-icon-lock" show-password></el-input>
        </el-form-item>
        <el-form-item class="btns">
          <el-button type="primary" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      form: {
        user: 'admin',
        password: '123456'
      },
      rules: {
        user: [
          {
            required: true,
            message: '请输入用户名',
            trigger: 'blur'
          },
          {
            min: 3,
            max: 5,
            message: '长度在 3 到 5 个字符',
            trigger: 'blur'
          }
        ],
        password: [
          {
            required: true,
            message: '请输入密码',
            trigger: 'blur'
          },
          {
            min: 6,
            max: 10,
            message: '长度在 6 到 10 个字符',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    resetLoginFrom () {
      this.$router.replace('/register')
    },
    login: function () {
      this.$refs.formRef.validate(valid => {
        if (valid) {
          if (this.form.user === 'admin' && this.form.password === '123456') {
            this.$message.success('登录成功！')
            localStorage.setItem('ms_username', this.form.user)
            this.$router.push('/use')
          } else if (this.form.user === 'man' && this.form.password === '111111') {
            this.$message.success('登录成功！')
            localStorage.setItem('ms_username', this.form.user)
            this.$router.push('/jingo')
          }
        } else {
          this.$message.error('登录失败')
        }
      })
    }
  }
}
</script>
<style >
.Login_container{
  height: 100%;
}
.Login_box{
  position: absolute;
  width: 430px;
  height: 400px;
  border-radius: 25px;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
  background: rgba(255, 255, 255, 0.3);
  overflow: hidden;
}
.Login_Form{
  position: absolute;
  bottom: 30px;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
}
.btns{
  display: flex;
  justify-content: flex-end;
}
h1{
  color: white;
}
</style>
